home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15119 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: beta.nedernet.nl!usenet
  2. From: jos@and.nl (Jos A. Horsmeier)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Memory deallocation and linked lists
  5. Date: 17 Apr 1996 10:26:59 GMT
  6. Organization: AND Operations Research B.V.
  7. Message-ID: <4l2h1j$lgd@beta.nedernet.nl>
  8. References: <4l1hpk$hk5@alice.walrus.com>
  9. NNTP-Posting-Host: klepzeiker.and.nl
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14. In article <4l1hpk$hk5@alice.walrus.com>, warrenj@walrus.com wrote:
  15.  
  16. |Greetings!
  17. |Let us suppose I have a singularly linked list.  If i free up the first 
  18. |node, will all of the rest of the nodes be freed up as well? Free 
  19. |meaning, using the borland command free().  Do I have to free up each node
  20. |seperately? Something I've never actually known >:). Thanks in advance.
  21.  
  22. Yes, you have to free every single element yourself. The reason is, that
  23. malloc(), after allocating the memory for you, doesn't know what this
  24. memory is going to be used for (and it couldn't care less actually ;-)
  25. So, if you're going to use this piece of memory as a list element,
  26. nobody else knows about it, i.e. nobody knows that there exists a pointer
  27. value stored in this piece of memory, pointing to another piece of memory ...
  28.  
  29. kind regards,
  30.  
  31. Jos aka jos@and.nl
  32. -- 
  33. Atnwgqkrl gy zit vgksr, ug qshiqwtzoeqs!
  34.  
  35.